<?php
require('../../../config/config.php');

// GET FILE ROUTINES

$file=$_FILES["file"]["tmp_name"];
//$file = "/disk2/www/ceditorial/system/example.txt";
//Later this file will be passed via POST to this file

// get contents of a file into a string
$rh = fopen($file, "r");
$contents = fread($rh, filesize($file));
fclose($rh);

// initialize variables
$CR = "\r\n";
$package="";
$class="";
$table="";
$php = false;
$mysql = false;
$admin = false;
$author="";
$version="";
$desc=array();
$var=array();


//parse the string
$contents = ereg_replace("\r","",$contents);
$lines = explode("\n",$contents);

for ($i=0;$i<count($lines);$i++){

	if (substr($lines[$i],0,1)=="@"){
		// we have to process something
		$command=explode(":",$lines[$i]);

		switch (strtolower($command[0])){
			case "@php":
				$php=true;
				break;
			case "@mysql":
				$mysql=true;
				break;
			case "@table":
				$table=$command[1];
				break;
			case "@admin":
				$admin=true;
				break;
			case "@package":
				$package=$command[1];
				break;
			case "@class":
				$class=$command[1];
				break;
			case "@author":
				$author=$command[1];
				break;
			case "@version":
				$version =$command[1];
				break;
			case "@desc":
				array_push($desc,$command[1]);
				break;
			case "@var":
				$tmp=array("name"=>$command[1],"type"=>$command[2],"length"=>$command[3],"default"=>$command[4],"extra"=>$command[5],"PK"=>$command[6]);
				array_push($var,$tmp);
				break;
		}
	}
}

// HERE WE CREATE THE CLASS OBJECT
echo "<HR>";
echo "THE CLASS FILE: $class.class.php<BR>";
echo "PACKAGE: $package";
echo "<HR>";
include("php.creator.php");
show($classFile);
echo "<HR>";
echo "THE MYSQL FILE";
echo "<HR>";

include("mysql.creator.php");
show($mysqlFile);
echo "<HR>";
echo "THE LISTING FILE: $class.list.php";
echo "<HR>";

include("admin.list.creator.php");
show($adminList);
echo "<HR>";
echo "THE EDIT FILE: $class.edit.php";
echo "<HR>";

include("admin.edit.creator.php");
show($adminEdit);
echo "<HR>";
echo "THE PROCESS FILE: $class.process.php";
echo "<HR>";

include("admin.delete.creator.php");
show($adminDelete);
echo "<HR>";
echo "THE PROCESS FILE: $class.delete.php";
echo "<HR>";

include("admin.process.creator.php");
show($adminProcess);

?>